﻿/*==============================================================
 * ArticleExtensions.cs
 * Copyright (C) 2014 贵州惠众互联 Inc. All rights reserved.
 *==============================================================
 * Author:   罗应红
 * Date:     2014/03/04 11:27:10.
 * Version:  1.0
 * QQ:		 88962800
*==============================================================*/

using System;
using System.Linq;
using QDT.Common;
using QDT.Core.Domain;
using QDT.Web.Admin.Models;

namespace QDT.Web.Admin.Helper {
    public static class ArticleExtensions {
         public static IPagedList<ArticleModel> ToModelList(this IPagedList<Article> source) {
             var result = source.Select(ToModel);
             return new StaticPagedList<ArticleModel>(result,source.PageIndex,source.PageSize,source.TotalItemCount);
         }
        public static ArticleModel ToModel(this Article article) {
            return new ArticleModel {
                CateId = article.CateId,
                Id = article.ID,
                IsEffect = article.IsEffect,
                Title = article.Title,
                Sort = article.Sort,
                Content = article.Content,
                IsDelete = article.IsDelete,
                Brief = article.Brief,
                CreateTime = article.CreateTime,
                AddAdminId = article.AddAdminId,
                CateName = article.Cate.Title,
                ClickCount =  article.ClickCount,
                RelUrl = article.RelUrl,
                SeoDescription = article.SeoDescription,
                SeoKeyWord = article.SeoKeyWord,
                SeoTitle =  article.SeoTitle,
                SubTitle = article.SubTitle,
                UName =  article.UName,
                photo = article.Photo,
                UpdateAdminId =  article.UpdateAdminId,
                UpdateTime = article.UpdateTime
                
            };
        }
        public static Article ToEntity(this ArticleModel model) {
            return new Article {
                IsEffect = model.IsEffect,
                Title = model.Title,
                Sort = model.Sort,
                Content = model.Content,
                ID = model.Id,
                IsDelete = model.IsDelete,
                Brief = model.Brief,
                CreateTime = DateTime.Now,
                AddAdminId = model.AddAdminId,
                ClickCount = model.ClickCount,
                RelUrl = model.RelUrl,
                SeoDescription =  model.SeoDescription,
                SeoKeyWord = model.SeoKeyWord,
                SeoTitle = model.SeoTitle,
                SubTitle = model.SubTitle,
                UName = model.UName,
                UpdateAdminId = model.UpdateAdminId,
                CateId = model.CateId,
                Photo = model.photo,
                UpdateTime = DateTime.Now
            };
        }
    }
}